package com.yn.yzq.controller;

import com.yn.yzq.entity.User;
import com.yn.yzq.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/demo")
public class Test {

    private static final Logger logger = LoggerFactory.getLogger(Test.class);

    @Autowired
    private UserService userService;

    @RequestMapping("/getInfo")
    @ResponseBody
    public Map<String, Object> getInfo(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        String username = request.getParameter("username");
        String password = request.getParameter("password");
//        String rememberme = request.getParameter("rememberme");
        User user = userService.getUserInfo(username);

        if (user != null && !user.equals("")) {
            logger.info(user.toString());
            map.put("客户信息", user);
        } else {
            map.put("errorMsg", "查无此人！");
        }
        return map;
    }

    @RequestMapping("/sayHi")
    @ResponseBody
    public String sayHi() {
        return "hi";
    }
}
